﻿
Imports DATA
Imports SERVICIOS

Public Class oFm_grupo


    Private WithEvents oGrupo As New grupo_data
    Private _Codigo As Integer = 0

    Private Sub oFm_grupo_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        Me.Dispose()
    End Sub

    Private Sub oFm_grupo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.TituloFormulario = "Crear/Modificar Grupos"
        EstructuraGrilla()
        CargaGrillaGrupos()
    End Sub

    Sub EstructuraGrilla()
        With oGr_datos
            .Cols_P = 2
            .Rows_P = 0
            .MaquillaGrilla()
            .ReadOnly = True
            .ColumnTextHeader(0, 60) = "id" : .ColVisible(0) = False
            .ColumnTextHeader(1, 300) = "Nombre"
            For i As Integer = 0 To .ColumnCount - 1
                .Columns(i).SortMode = DataGridViewColumnSortMode.Automatic
            Next
        End With
    End Sub

    Sub CargaGrillaGrupos()
        oGr_datos.Rows.Clear()
        Dim dt As DataTable = oGrupo.GetData
        If Not IsNothing(dt) Then
            If dt.Rows.Count > 0 Then
                With oGr_datos
                    oGr_datos.Rows_P = dt.Rows.Count
                    For i As Integer = 0 To dt.Rows.Count - 1
                        .TextMatrix(i, 0) = dt.Rows(i).Item("GRUPO_ID")
                        .TextMatrix(i, 1) = dt.Rows(i).Item("GRUPO_NOMBRE")
                    Next
                End With
            End If
        End If
    End Sub

    Sub Limpiar()
        _Codigo = 0
        oTx_nombre.Text = ""
    End Sub

    Private Sub oGrupo_ErrorServer(Descripcion As String) Handles oGrupo.ErrorServer
        MsgBox(Descripcion, MsgBoxStyle.Critical, Me.Text)
    End Sub

    Private Sub oGrupo_GuardaCorrecto() Handles oGrupo.GuardaCorrecto
        Limpiar()
        CargaGrillaGrupos()
    End Sub

    Private Sub oPb_Salir_Click(sender As Object, e As EventArgs) Handles oPb_Salir.Click
        Me.Close()
    End Sub

    Private Sub oPb_guardar_Click(sender As Object, e As EventArgs) Handles oPb_guardar.Click
        oGrupo.minGuarda(_Codigo, oTx_nombre.Text)
    End Sub

    Private Sub oGr_datos_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles oGr_datos.CellDoubleClick
        With oGr_datos
            If .Rows_P > 0 Then
                _Codigo = .TextMatrix(.Row, 0)
                oTx_nombre.Text = .TextMatrix(.Row, 1)
            End If
        End With
    End Sub
End Class
